import { $post } from '@/utils/request-1'
const state = {
  data: {
    'name': '',
    'french': '',
    'price': '0',
    'tid': 0,
    'tname': '',
    'timg': '',
    'chineseBrief': '1磅保温包和2磅保温包',
    'fid': null,
    'fname': null,
    'sid': null,
    'sname': null,
    'saleTotal': 0,
    'bcid': 5,
    'bcname': '配件',
    'weight': '',
    'goodsTips': '',
    'useFlg': 1,
    'pprice': '10.00',
    'img': 'https://xecho.oss-cn-hangzhou.aliyuncs.com/blog/a1ec08fa513d26978d236df15bfbb2fb4216d8ae.png',
    'sku': 'PJ0318',
    'spec': '2磅保温包',
    'limg': '',
    'fittings': '',
    'list': [
      {
        'id': 17464,
        'sku': 'PJ0316',
        'ahead': '提前5小时预定',
        'edible': '',
        'spec': '1磅保温包',
        'price': '10.00',
        'size': '30cm*29cm*21cm',
        'bcid': 5,
        'bcname': '配件',
        'weight': '',
        'useFlg': 1,
        'pprice': '10.00',
        'fittings': '',
        'pic': {
          'url': '',
          'list': []
        }
      }
    ]
  },
  img: []
}

const mutations = {
  dataCatch(state, obj) {
    ({ name: state.data.name,
      bcid: state.data.bcid,
      chineseBrief: state.data.chineseBrief,
      price: state.data.price,
      list: state.data.list
    } = obj)
    state.data.bcid = Number(state.data.bcid)

    if (state.img.length) {
      state.data.list[0].pic.list = state.img
      state.data.img = state.img[0].url
    } else {
      state.img = [{ name: 'cake.png', url: 'https://xecho.oss-cn-hangzhou.aliyuncs.com/blog/a1ec08fa513d26978d236df15bfbb2fb4216d8ae.png' }, { name: 'cake.png', url: 'https://xecho.oss-cn-hangzhou.aliyuncs.com/blog/a1ec08fa513d26978d236df15bfbb2fb4216d8ae.png' }]
      state.data.list[0].pic.list = state.img
      state.data.img = state.img[0].url
    }

    $post('/1.1/classes/cake', { ...state.data })
    // console.log({ ...state.data })
  },
  imgCatch(state, obj) {
    state.img = obj
  }

}

const actions = {
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
